#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#include<sys/types.h>

int main()
{
  pid_t id = fork();
  if(id == 0)
  {
    //child
    printf("I am child. pid: %d ppid: %d\n", getpid(), getppid());
    char* const my_env[] = {
      "MYENV=helloworld!",
       NULL
    };
    execle("./mycmd", "mycmd", NULL, my_env);
    exit(1);
  }
  //father
  int status = 0;
  pid_t ret = waitpid(id, &status, 0);
  if(ret > 0)
  {
    printf("wait success! sig: %d code: %d\n", status&0x7F, (status>>8)&0xFF);
  }
  else{
    printf("wait error\n");
  }
  return 0;
}
